<?php

class Core_Controller_Admincp_Form_Item_Add extends Nuo_Controller_Admincp
{
	function execute($request)
	{
		$table = Nuo::getTable('core/html/item');

		$form = Nuo::getObject('core/admincp/form/additem', 'form');

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item = $table -> fetchNew();

			$item -> fromArray($data);

			$item -> updated_at = time();

			$item -> save();

			Nuo_Messenger::instance()->add(Intl::__('Updated!'));
			
			$mainForm  = Nuo::getTable('core/html/form')->find($item->form_id)->current();
			
			Nuo_Form::removeCache($mainForm->form_key);
			
			Nuo::redirect('admincp/core/form/item', array('form_id' => $item -> form_id));
		}

		return  Nuo::getView()->render('core/view/controller/admincp/edit', array('form' => $form));
	}

}
